<?php include 'login/Restrito.php';?>
<script language="JavaScript" type="text/javascript">
   function mascaraCpf(campoCpf){
              var cpf = campoCpf.value;
              if (cpf.length == 3){
                  cpf = cpf + '.';
                  document.forms[0].cpf.value = cpf;
      				return true;              
              }
              if (cpf.length == 7){
                  cpf = cpf + '.';
                  document.forms[0].cpf.value = cpf;
                  return true;
              }
			  if (cpf.length == 11){
                  cpf = cpf + '-';
                  document.forms[0].cpf.value = cpf;
                  return true;
              }
         }
   function mascaraRG(campoRG){
       var rg = campoRG.value;
       if (rg.length == 3){
           rg = rg + '.';
           document.forms[0].rg.value = rg;
				return true;              
       }
       if (rg.length == 7){
           rg = rg + '.';
           document.forms[0].rg.value = rg;
           return true;
       }
  }
	function caractereTelefone(campoTel){
              var telefone = campoTel.value;
              if (telefone.length == 3){
                  telefone = telefone + ')';
                  document.forms[0].fone.value = telefone;
      				return true;              
              }
              if (telefone.length == 8){
                  telefone = telefone + '-';
                  document.forms[0].fone.value = telefone;
                  return true;
              }
			  
         }
	function caractereCelular(campoCel){
        var celular = campoCel.value;
        if (celular.length == 3){
            celular = celular + ')';
            document.forms[0].celular.value = celular;
				return true;              
        }
        if (celular.length == 8){
            celular = celular + '-';
            document.forms[0].celular.value = celular;
            return true;
        }
		  
   }
	function caractereData(campoData){
        var data = campoData.value;
        if (data.length == 2){
            data = data + '/';
            document.forms[0].datanasc.value = data;
				return true;              
        }
        if (data.length == 5){
            data = data + '/';
            document.forms[0].datanasc.value = data;
            return true;
        }
		  
   }
</script>
<?php 
    	$id = $_GET['id'];
    	require_once  "banco/ConexaoBanco.php";
    	
    	$sql = mysql_query("SELECT * FROM paciente WHERE id_paciente = $id");
    	$dados = mysql_fetch_array($sql);
    	
    	function convertDataEmDMA($dt)
    	{
    		$dia = substr($dt,8,2);
    		$mes = substr($dt,5,2);
    		$ano = substr($dt,0,4);
    		$data = $dia."/".$mes."/".$ano;
    		return $data;
    	}
    ?>
<div id="conteudo">
	
	<div align="center">
    
    <form action="paciente/PacienteEditar.php" method="post">
    <h3 align="center">Editar dados do Paciente</h3>
  	<hr color="#0066FF" size="3px">
    <br />
    <div align="center" style="min-height: 350px; width:auto">
      <table width="850" border="0" align="center">
      
      <tr>
            <td width="150" align="left"><div align="left">Nome</div></td>
            <td width="700"><input name="nome" type="text" size="60" value="<?php echo $dados['p_nome']; ?>"/></td>
          </tr>
          <tr>
          	<td align="left">Sexo</td>
            <td><select name="sexo" >
            	<?php if($dados['p_sexo'] == 'Masculino'){
            		echo '<option value="Masculino" selected>Masculino</option>
                			<option value="Feminino">Feminino</option>';
            		
            	}
            	if($dados['p_sexo'] == 'Feminino'){
            		echo '<option value="Masculino">Masculino</option>
                			<option value="Feminino" selected>Feminino</option>';
            	}
            	?>
                </select>
            </td>
          </tr>
          <tr>
            <td align="left">Telefone</td>
            <td><input type="text" id="tel" name="fone" maxlength="13" value="<?php echo $dados['p_telefone']; ?>" /><font size="2" color="#555"> Ex: (XX)0000-0000 </font> </td>
          </tr>
          <tr>
            <td align="left">Celular</td>
            <td><input type="text" name="celular" maxlength="13" value="<?php echo $dados['p_celular']; ?>" /><font size="2" color="#555"> Ex: (XX)0000-0000 </font></td>
          </tr>
          <tr>
            <td>Email</td>
            <td><input type="text" name="email" size="40" value="<?php echo $dados['p_email']; ?>"/></td>
          </tr>
          <tr>
            <td align="left">Data de Nascimento</td>
            <td><input name="datacadastro" type="hidden" value="<?php echo convertDataEmDMA($dados['p_data_cadastro']); ?>"/><input name="datanasc" type="text" maxlength="10" id="data" value="<?php echo convertDataEmDMA($dados['p_data_nascimento']); ?>"/> <font size="2" color="#555"> Ex: 12/12/2012 </font> </td>
          </tr>
          <tr>
            <td align="left">RG</td>
            <td><input type="text" id="rg" name="rg" maxlength="11" value="<?php echo $dados['p_rg']; ?>"/><font size="2" color="#555"> Ex: 000.000.000 </font> </td>
          </tr>
          <tr>
            <td align="left">CPF</td>
            <td><input type="text" id="cpf" name="cpf" maxlength="14" value="<?php echo $dados['p_cpf']; ?>"/><font size="2" color="#555"> Ex: 000.000.000-00 </font> </td>
          </tr>
          <tr><td>Estado Civil</td>
          	<td>
          		<select name="estadocivil">
          			<option value="<?php echo $dados['p_estadocivil']; ?>"><?php echo $dados['p_estadocivil'];?></option>
          			<option value="Solteiro">Solteiro(a)</option>
          			<option value="Casado">Casado(a)</option>
          			<option value="Divorciado">Divorciado(a)</option>
          			<option value="Amasiado">Amasiado(a)</option>
          			<option value="Viúvo">Viúvo(a)</option>
          		</select>
          	</td>
          </tr>
          <tr>
          	<td>Profissão</td>
          	<td><input type="text" name="profissao" size="60" value="<?php echo $dados['p_profissao']; ?>"></td>
          </tr>
          <tr>
          	<td>Endereço</td>
          	<td><input type="text" name="endereco" size="60" value="<?php echo $dados['p_endereco']; ?>"><font size="2" color="#555" > Ex: Rua Arruda com sete copas, numero 10 </font></td>
          </tr>
          <tr>
          	<td>CEP</td>
          	<td><input type="text" name="cep" maxlength="8" value="<?php echo $dados['p_cep']; ?>"><font size="2" color="#555"> Somente numeros, ex:79370000 </font></td>
          </tr>
          <tr>
          	<td>Bairro</td>
          	<td><input type="text" name="bairro" size="60" value="<?php echo $dados['p_bairro']; ?>"></td>
          </tr>
          <tr>
          	<td>Cidade</td>
          	<td><input type="text" name="cidade" size="60" value="<?php echo $dados['p_cidade'];?>">
          	</td>
          </tr>
          <tr>
          	<td>Estado</td>
          	<td>
          		<select name="estado" >
          			<option value="<?php echo $dados['estado_id']; ?>">Selecione...</option>
          			<?php
							require_once "banco/ConexaoBanco.php";
							$query = mysql_query("SELECT * FROM estado");
							while($lista = mysql_fetch_array($query)) { ?> 
							<option value="<?php echo $lista['id_estado'] ?>"><?php echo $lista['nome'] ?></option>
						<?php } mysql_close();?>
          		</select>
          	
          	</td>
          </tr>
          <tr>
          	<td>Convenio</td>
          	<td><select name="convenio" >
          			<option value="<?php echo $dados['convenio_id']; ?>">Selecione...</option>
          			<?php
							require "banco/ConexaoBanco.php";
							$query = mysql_query("SELECT * FROM convenio");
							while($lista = mysql_fetch_array($query)) { ?> 
							<option value="<?php echo $lista['id_convenio']; ?>"><?php echo $lista['conv_nome'] ."-".$lista['conv_tipo']; ?></option>
						<?php } mysql_close();?>
          		</select>
          	
          	</td>
          </tr>
          <tr>
          	<td>Status</td>
          	<td><select name="status" >
          	<?php 
          			if ($dados['p_status'] == '1') {
          				echo '<option value="1" selected>Ativo</option>
          					  <option value="0">Inativo</option>';
          			}if ($dados['p_status'] == '0') {
          				echo '<option value="1" >Ativo</option>
          					  <option value="0" selected>Inativo</option>';
          			}
          	
          	?>
          		</select>
          	</td>
          </tr>
          <tr>
            <td align="left">&nbsp;</td>
            <td><input type="hidden" name="id" value="<?php echo $id;?>"><input type="submit" value="Editar" name="enviar" class="botao"/> </td>
          </tr>
        </table>
        </div>
      
    </form>
    
    </div>
</div>
